package com.wys.singleton_demo.lazy;

/**
 * @author godShan
 * @Description: 双层检查单例模式
 * @date 2019/5/5 11:20
 */
//优点 线程安全 性能比 锁加载方法上面好一点
//缺点 不能防止反序列化
public class DoubleCheckSingleton {

    private static DoubleCheckSingleton INSTANCE;

    private DoubleCheckSingleton() {
    }

    public synchronized static DoubleCheckSingleton getInstance() {
        if (INSTANCE == null) {
            synchronized (DoubleCheckSingleton.class) {
                if (INSTANCE == null) {
                    INSTANCE = new DoubleCheckSingleton();
                }
            }
        }
        return INSTANCE;
    }

}
